<?php
$title = 'Thêm sản phẩm';
$this->headTitle($title);
?>
<div class="hero-unit">
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('product', array('action'=>'add')));
$form->prepare();

echo $this->form()->openTag($form); ?>

<div class="form-element">
    <?php $element = $form->get('name'); ?>
    <?php echo $this->formLabel($element); ?>
    <?php echo $this->formInput($element); ?>
    <?php echo $this->formElementErrors($element); ?>
</div>

<div class="form-element">
    <?php $element = $form->get('image_name'); ?>
    <?php echo $this->formLabel($element); ?>
    <input type="file" id="file_upload"/>
    <img id="photoMainPreview" src="<?php echo $this->basePath()?>/backend/images/product-image.jpg" width="50px" height="50px">
    <?php echo $this->formInput($element); ?>
    <?php echo $this->formElementErrors($element); ?>
</div>

<p>
<?php echo $this->formSubmit($form->get('submit')); ?>
</p>

<?php echo $this->form()->closeTag(); ?>
</div>
<script src="<?php echo $this->basePath();?>/plugins/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php echo $this->basePath();?>/plugins/uploadify/uploadify.css">
<script type="text/javascript">
	<?php $timestamp = time(); ?>
	$(function() {
		$('#file_upload').uploadify({
			'formData'     : {
				'timestamp' : '<?php echo $timestamp; ?>',
				'token'     : '<?php echo md5('unique_salt' . $timestamp); ?>'
			},
			'swf'      : '<?php echo $this->basePath();?>/plugins/uploadify/uploadify.swf',
			'uploader' : '<?php echo $this->url('upload'); ?>',
			'onUploadSuccess' : function(file, data, response) {
 				console.log(data);
 				//console.log(data);console.log(file);
// 	            alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
				$('#image_name').val(file.name);
				$('#photoMainPreview').attr('src', '<?php echo $this->basePath();?>/files/'+file.name);
	        }
		});
	});
</script>